//
//  LHXanimationModel.m
//  blackViewC
//
//  Created by 林浩翔 on 16/5/24.
//  Copyright © 2016年 林浩翔. All rights reserved.
//

#import "LHXanimationModel.h"


@implementation LHXanimationModel 


//转场动画控制器

//动画的时间
- (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext{
    return 0.5;
}

//动画是怎样执行的
//无论是弹出还是销毁，如果有动画，都会调用下面的方法。
- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext{
    
    //1. 获取目的控制器
    if (self.presented) {
        
        UIView *ToView = [transitionContext viewForKey:UITransitionContextToViewKey];
        ToView.frame = CGRectMake(-ToView.frame.size.width,0,ToView.frame.size.width, ToView.frame.size.height);

        [UIView animateWithDuration:0.2 animations:^{

            ToView.frame = CGRectMake(0, 0, ToView.frame.size.width, ToView.frame.size.height);
            
        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];
    }else{
        
        UIView *FromView = [transitionContext viewForKey:UITransitionContextFromViewKey];
        FromView.frame = CGRectMake(0, FromView.frame.origin.y, FromView.frame.size.width, FromView.frame.size.height);

        [UIView animateWithDuration:0.2 animations:^{
            FromView.frame = CGRectMake(-FromView.frame.size.width,FromView.frame.origin.y,FromView.frame.size.width, FromView.frame.size.height);

        } completion:^(BOOL finished) {
            [transitionContext completeTransition:YES];
        }];
        
        
        
    }

    
    
    
}



@end
